package com.mappn.backup;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.mappn.backup.util.Const;

public class AlarmReceiver extends BroadcastReceiver {

	@SuppressWarnings("static-access")
	@Override
	public void onReceive(Context context, Intent intent) {
		if (Const.MY_ALARM_ACTION.equals(intent.getAction()) && !Main.isRunning) {
			NotificationManager notificationManager = (NotificationManager) context
					.getSystemService(context.NOTIFICATION_SERVICE);
			Notification notification = new Notification();
			notification.icon = R.drawable.icon;
			notification.tickerText = "您已经很久没备份您的数据了";
			Intent intent1 = new Intent(context, Main.class);
			intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
					| Intent.FLAG_ACTIVITY_NEW_TASK);

			PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
					intent1, 0);
			notification.setLatestEventInfo(context, context.getResources()
					.getString(R.string.app_name), "您已经很久没有备份了，请备份您的数据",
					pendingIntent);
			notification.flags |= Notification.FLAG_AUTO_CANCEL;
			notificationManager.notify(3470, notification);
		}
	}
}
